﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace MoviesWebsite.Models
{
    public class MoviesModelInitializer : DropCreateDatabaseIfModelChanges<MoviesModel> //DropCreateDatabaseAlways<MoviesModel> 
    {
        protected override void Seed(MoviesModel context)
        {
            // Create movies
            var donnieDarko = new Movie { Name = "Donnie Darko", Tags = new List<Tag> { "Quirky", "Weird", "Cool" } };
            var avatar = new Movie { Name = "Avatar", Tags = new List<Tag> { "3D spectacle" } };
            var topGun = new Movie { Name = "Top Gun", Tags = new List<Tag> { "F14", "Tomcat", "Cheesy" } };
            var mrAndMrsSmith = new Movie { Name = "Mr and Mrs Smith", Tags = new List<Tag> { "Guns", "Infidelity" } };
            var alien = new Movie { Name = "Alien", Tags = new List<Tag> { "Eww" } };
            var aliens = new Movie { Name = "Aliens", Tags = new List<Tag> { "They're everywhere man" } };
            
            context.Movies.Add(donnieDarko);
            context.Movies.Add(avatar);
            context.Movies.Add(topGun);
            context.Movies.Add(mrAndMrsSmith);
            context.Movies.Add(alien);
            context.Movies.Add(aliens);

            // Create genres and link to movies
            var action = new Genre { Name = "Action" };
            var drama = new Genre { Name = "Drama" };
            var scifi = new Genre { Name = "Sci-Fi" };
            var romance = new Genre { Name = "Romance" };

            donnieDarko.Genre = drama;
            avatar.Genre = action;
            topGun.Genre = action;
            alien.Genre = scifi;
            mrAndMrsSmith.Genre = romance;
            aliens.Genre = scifi;


            // Create Actors and Directors and link to movies
            var tomCruise = new Star { Firstname = "Tom", Surname = "Cruise", Agent="Mr Jones"};
            var jakeGyllenhaal = new Actor { Firstname = "Jake", Surname = "Gyllenhaal" };
            var kellyMcGillis = new Actor { Firstname = "Kelly", Surname = "McGillis" };
            var maggieGyllenhaal = new Actor { Firstname = "Maggie", Surname = "Gyllenhaal" };
            var samWorthington = new Actor { Firstname = "Sam", Surname = "Worthington" };
            var zoeSaldana = new Actor { Firstname = "Zoe", Surname = "Saldana" };
            var bradPitt = new Actor { Firstname = "Brad", Surname = "Pitt" };
            var angelinaJolie = new Actor { Firstname = "Angelina", Surname = "Jolie" };
            var sigourneyWeaver = new Actor { Firstname = "Sigourney", Surname = "Weaver" };

            var jamesCameron = new Director { Firstname = "James", Surname = "Cameron" };
            var tonyScott = new Director { Firstname = "Tony", Surname = "Scott" };
            var richardKelly = new Director { Firstname = "Richard", Surname = "Kelly" };
            var ridleyScott = new Director { Firstname = "Ridley", Surname = "Scott" };
            var dougLiman = new Director { Firstname = "Doug", Surname = "Liman" };

            donnieDarko.Actors = new List<Actor> { jakeGyllenhaal, maggieGyllenhaal };
            donnieDarko.Director = richardKelly;

            avatar.Actors = new List<Actor> { samWorthington, zoeSaldana, sigourneyWeaver };
            avatar.Director = jamesCameron;

            topGun.Actors = new List<Actor> { tomCruise, kellyMcGillis };
            topGun.Director = tonyScott;

            alien.Actors = new List<Actor> { sigourneyWeaver };
            alien.Director = ridleyScott;

            mrAndMrsSmith.Actors = new List<Actor> { tomCruise, angelinaJolie };
            mrAndMrsSmith.Director = dougLiman;

            aliens.Actors = alien.Actors;
            aliens.Director = jamesCameron;

            // Create Users and their Rental History and their Ratings
            var alex = new User
            {
                Username = "alexj",
                IsAdministrator = true,
                Rentals = new List<UserRental>{
                     new UserRental {CheckedOut = new DateTime(2010,11,20), CheckedIn = new DateTime(2010,11,25), Movie = avatar},
                     new UserRental {CheckedOut = DateTime.Today.AddDays(-5), Movie = donnieDarko }
                },
                Ratings = new List<UserRating> { 
                    new UserRating { Movie = donnieDarko, Rating = 5 },
                    new UserRating { Movie = avatar, Rating = 4}
                }
            };
            var pablo = new User
            {
                Username = "pablocas",
                IsAdministrator = false,
                Rentals = new List<UserRental>{
                     new UserRental {CheckedOut = new DateTime(1995,5,10), CheckedIn = new DateTime(1995,5,15), Movie = topGun},
                     new UserRental {CheckedOut = DateTime.Today.AddDays(-5), Movie = mrAndMrsSmith }
                },
                Ratings = new List<UserRating> { 
                    new UserRating { Movie = topGun, Rating = 3 },
                    new UserRating { Movie = mrAndMrsSmith, Rating = 4}
                }
            };

            context.Users.Add(alex);
            context.Users.Add(pablo);

        }
    }
}